package jni;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.ptr.DoubleByReference;
import org.junit.Test;

public class JnaTest
{

    public interface CLibrary extends Library
    {

        CLibrary INSTANCE = (CLibrary) Native.load("D:\\myapp\\testrczs\\src\\main\\lib\\Win32Project1.dll", JnaTest.CLibrary.class);
        //申明要调用的dll中的方法（可以是多个方法）
        //JNA调用除法一直出现3647385435-E，原来是方法名字不对，原来div不可用，换成diver
        public double diver(DoubleByReference i, DoubleByReference j);
        public double mul(DoubleByReference i, DoubleByReference j);
        public double sub(DoubleByReference i, DoubleByReference j);
        public double add(DoubleByReference i, DoubleByReference j);
    }




    public static void main(String[] args)
    {
        DoubleByReference dou1 = new DoubleByReference(50.0);
        DoubleByReference dou2 = new DoubleByReference(20.0);

        System.out.println(CLibrary.INSTANCE.add(dou1,dou2));
        System.out.println(CLibrary.INSTANCE.mul(dou1,dou2));
        System.out.println(CLibrary.INSTANCE.sub(dou1,dou2));
        System.out.println(CLibrary.INSTANCE.diver(dou1,dou2));
    }

    @Test
    public void test() {
        System.out.println(System.getProperty("java.library.path"));
    }
}
